'use strict';
const db = uniCloud.database()
// const dbCmd = db.command
exports.main = async (event, context) => {
	const collection = db.collection('traveler');
	const id = event.id;
	const filter = {
		_id:id
	}
	if(id){
		const docList = await collection.where(filter)
		.limit(1).get();
		if (!docList.data || docList.data.length === 0) {
			return {
				status: 0,
				msg: '没有查找到该数据！'
			}
		}else{
			const update={
				certificateType:event.certificateType,
				certificateNum:event.certificateNum,
				name:event.name,
				sex:event.sex
			}
			const res = await collection.doc(id).update(update);
			if (res.updated === 1) {
				let result = Object.assign({}, {
					_id: docList.data[0]._id,
					status: 1,
					msg: '编辑成功'
				}, event)
				return result;
			} else {
				return {
					status: 0,
					msg: '没有查找到该数据!'
				}
			}
		}
	}else{
		return {
			status: 0,
			msg: 'id不能为空！'
		}
	}
};